package com.huike.web.controller.contract;

import com.huike.common.constant.UserConstants;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.entity.SysUser;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContractWy;
import com.huike.contract.domain.TbContractWyVo;
import com.huike.contract.service.ITransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/transfer")
public class TransferController extends BaseController {
@Autowired
private ITransferService iTransferService;

    @GetMapping("/list")
    public TableDataInfo getTransfer(TbContractWy wy) throws Exception{

        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
        Date date=dateformat.parse("2020-04-19");
        wy.setBeginTime(date);
        wy.setEndTime(new Date());

       List<TbContractWyVo>sy =iTransferService.selectByTbCon(wy);

        return getDataTable(sy);
    }

    @PutMapping("/assignment/{type}/{uname}/{yname}")
    public AjaxResult updateFer(@PathVariable("type")Integer type, Integer uid, @PathVariable("yname")Integer yid) {
        uid = 232;
        System.out.println(yid);
        String uName = iTransferService.selectuserByUserId(uid);
        String yName = iTransferService.selectuserByUserId(yid);


        if (type == 0) {
            int i = iTransferService.updateFromClue(uName, yName);
           return AjaxResult.success("线索转派成功");
        } else if(type==1){
            int i = iTransferService.updateFromBusiness(uName, yName);
           return AjaxResult.success("商机转派成功");
        }


        return AjaxResult.error("数据传输有误");
    }
}